package com.zhoufeng.udp.cient;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

import com.zhoufeng.common.Common;
import com.zjhbkj.xinfen.commom.Global;
import com.zjhbkj.xinfen.model.SendComsModel;
import com.zjhbkj.xinfen.util.CommandUtil;

public class UDPClient {

	public static void main(String[] args) throws IOException, InterruptedException {
//		DatagramSocket client = new DatagramSocket();
//		//SendComsModel localRcvComsModel = new SendComsModel();
////		String s = "40 DA 24 00 01 05 54 00 51 00 A0 02 00 16 0D 02 24 FF FF FF B7 AB";
////		String s = "40 9A 11 24 22 33 54 22 00 00 00 00 00 00 00 00 00 FF FF FF 4E AB";
//		String s = "40 DA FE 13 01 11 26 00 35 00 A0 02 5C 15 E9 82 25 FF FF BA 2C AB";
////		String s = "AA EA 03 28 02 01 2E 13 1B 04 0F 1E 08 1E 15 03 82 FF FF FF 33 AB";
////		System.out.println(s.length());
//		byte[] sendBuf;
//		//sendBuf = s.getBytes();
//		sendBuf  = CommandUtil.getCommand(s);
//
//		System.out.println(sendBuf.length);
//		InetAddress addr = InetAddress.getByName("127.0.0.1");
////		InetAddress addr = InetAddress.getByName("122.112.65.143");
////		InetAddress addr = InetAddress.getByName("115.159.71.155");
//
//		int port = 5000;
//		DatagramPacket sendPacket = new DatagramPacket(sendBuf, sendBuf.length, addr, port);
//
//		client.send(sendPacket);
//
//		byte[] recvBuf = new byte[Common.COMMAND_LENGTH];
//		DatagramPacket recvPacket = new DatagramPacket(recvBuf, recvBuf.length);
//		client.receive(recvPacket);
////		String recvStr = new String(recvPacket.getData(), 0, recvPacket.getLength());
//		String recvStr = CommandUtil.bytesToHexString(recvPacket.getData()); // new String(recvPacket.getData(), 0, recvPacket.getLength());
//		System.out.println("收到:" + recvStr);
//		client.close();
		
		
		for(int i = 0 ; i < 5; i++){
			ClientThread ct = new ClientThread();
			ct.setCount(i);
			Thread th = new Thread(ct);
			th.run();
			Thread.sleep(5000);
		}
		
		
		
		
		

	}
	
	
	public static byte[] ObjectToByte(java.lang.Object obj) throws IOException {  
		byte[] by = null;
		ByteArrayOutputStream bs = new ByteArrayOutputStream();
		ObjectOutputStream bo = new ObjectOutputStream(bs);
		bo.writeObject(obj);
		by = bs.toByteArray();
		System.out.println(by.length);
		return by;
	}  
	
	
	

}
